package com.lmpop.trade.tb_commpara;

import com.lmpop.frame.QueryList;
import com.lmpop.frame.SysMap;
import com.lmpop.frame.TradeInterf;
import com.lmpop.frame.dao.DbmInterf;
import com.lmpop.frame.exp.ApplicationException;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;

public class Tb_commparaInfo implements TradeInterf
{
  QueryList queryList;

  public Tb_commparaInfo()
  {
    this.queryList = new QueryList();
  }

  public SysMap insert(DbmInterf dbmMgr, SysMap map)
  {
    Tb_commpara tb_commpara = new Tb_commpara();
    tb_commpara.setParam_id(map.getString("param_id"));
    tb_commpara.setSubsys_code(map.getString("subsys_code"));
    tb_commpara.setParam_attr(map.getInt("param_attr"));
    tb_commpara.setParam_code(map.getString("param_code"));
    tb_commpara.setParam_name(map.getString("param_name"));
    tb_commpara.setPara_code1(map.getString("para_code1"));
    tb_commpara.setPara_code2(map.getString("para_code2"));
    tb_commpara.setPara_code3(map.getString("para_code3"));
    tb_commpara.setPara_code4(map.getString("para_code4"));
    tb_commpara.setPara_code5(map.getString("para_code5"));
    tb_commpara.setPara_code6(map.getString("para_code6"));
    tb_commpara.setPara_code7(map.getString("para_code7"));
    tb_commpara.setPara_code8(map.getString("para_code8"));
    tb_commpara.setPara_code9(map.getString("para_code9"));
    tb_commpara.setPara_code10(map.getString("para_code10"));
    tb_commpara.setPara_code11(map.getString("para_code11"));
    tb_commpara.setPara_code12(map.getString("para_code12"));
    tb_commpara.setPara_code13(map.getString("para_code13"));
    tb_commpara.setPara_code14(map.getString("para_code14"));
    tb_commpara.setPara_code15(map.getString("para_code15"));
    tb_commpara.setPara_code16(map.getString("para_code16"));
    tb_commpara.setPara_code17(map.getString("para_code17"));
    tb_commpara.setPara_code18(map.getString("para_code18"));
    tb_commpara.setPara_code19(map.getString("para_code19"));
    tb_commpara.setPara_code20(map.getString("para_code20"));
    tb_commpara.setPara_code21(map.getString("para_code21"));
    tb_commpara.setPara_code22(map.getString("para_code22"));
    tb_commpara.setPara_code23(map.getString("para_code23"));
    tb_commpara.setPara_code24(map.getString("para_code24"));
    tb_commpara.setPara_code25(map.getString("para_code25"));
    tb_commpara.setPara_code26(map.getString("para_code26"));
    tb_commpara.setPara_code27(map.getString("para_code27"));
    tb_commpara.setPara_code28(map.getString("para_code28"));
    tb_commpara.setPara_code29(map.getString("para_code29"));
    tb_commpara.setPara_code30(map.getString("para_code30"));
    tb_commpara.setStart_date(map.getString("start_date"));
    tb_commpara.setEnd_date(map.getString("end_date"));
    tb_commpara.setRemark(map.getString("remark"));
    tb_commpara.setUpdate_staff_id(map.getString("update_staff_id"));
    tb_commpara.setUpdate_depart_id(map.getString("update_depart_id"));
    tb_commpara.setUpdate_time(map.getString("update_time"));

    String result_code = "0";
    try {
      insert(dbmMgr, tb_commpara);
    } catch (ApplicationException e) {
      e.printStackTrace();
      result_code = "1";
    }
    map.setString("result_code", result_code);
    return map;
  }

  public void insert(DbmInterf dbmMgr, Tb_commpara tb_commpara)
    throws ApplicationException
  {
    dbmMgr.update("insertTb_commpara", tb_commpara);
  }

  public SysMap delete(DbmInterf dbmMgr, SysMap map)
  {
    String pkid_string = map.getString("pkid");
    String result_code = "0";
    try {
      if (!pkid_string.equals("")) {
        String[] pkStr = pkid_string.split("\\|");
        for (int i = 0; i < pkStr.length; i++) {
          if (pkStr[i].equals("")) continue; delete(dbmMgr, pkStr[i]);
        }
      }
    } catch (ApplicationException e) {
      e.printStackTrace();
      result_code = "1";
    }
    map.setString("result_code", result_code);
    return map;
  }

  public void delete(DbmInterf dbmMgr, String pkid)
    throws ApplicationException
  {
    dbmMgr.update("deleteTb_commpara", pkid);
  }

  public SysMap update(DbmInterf dbmMgr, SysMap map)
  {
    Tb_commpara tb_commpara = new Tb_commpara();
    tb_commpara.setParam_id(map.getString("param_id"));
    tb_commpara.setSubsys_code(map.getString("subsys_code"));
    tb_commpara.setParam_attr(map.getInt("param_attr"));
    tb_commpara.setParam_code(map.getString("param_code"));
    tb_commpara.setParam_name(map.getString("param_name"));
    tb_commpara.setPara_code1(map.getString("para_code1"));
    tb_commpara.setPara_code2(map.getString("para_code2"));
    tb_commpara.setPara_code3(map.getString("para_code3"));
    tb_commpara.setPara_code4(map.getString("para_code4"));
    tb_commpara.setPara_code5(map.getString("para_code5"));
    tb_commpara.setPara_code6(map.getString("para_code6"));
    tb_commpara.setPara_code7(map.getString("para_code7"));
    tb_commpara.setPara_code8(map.getString("para_code8"));
    tb_commpara.setPara_code9(map.getString("para_code9"));
    tb_commpara.setPara_code10(map.getString("para_code10"));
    tb_commpara.setPara_code11(map.getString("para_code11"));
    tb_commpara.setPara_code12(map.getString("para_code12"));
    tb_commpara.setPara_code13(map.getString("para_code13"));
    tb_commpara.setPara_code14(map.getString("para_code14"));
    tb_commpara.setPara_code15(map.getString("para_code15"));
    tb_commpara.setPara_code16(map.getString("para_code16"));
    tb_commpara.setPara_code17(map.getString("para_code17"));
    tb_commpara.setPara_code18(map.getString("para_code18"));
    tb_commpara.setPara_code19(map.getString("para_code19"));
    tb_commpara.setPara_code20(map.getString("para_code20"));
    tb_commpara.setPara_code21(map.getString("para_code21"));
    tb_commpara.setPara_code22(map.getString("para_code22"));
    tb_commpara.setPara_code23(map.getString("para_code23"));
    tb_commpara.setPara_code24(map.getString("para_code24"));
    tb_commpara.setPara_code25(map.getString("para_code25"));
    tb_commpara.setPara_code26(map.getString("para_code26"));
    tb_commpara.setPara_code27(map.getString("para_code27"));
    tb_commpara.setPara_code28(map.getString("para_code28"));
    tb_commpara.setPara_code29(map.getString("para_code29"));
    tb_commpara.setPara_code30(map.getString("para_code30"));
    tb_commpara.setStart_date(map.getString("start_date"));
    tb_commpara.setEnd_date(map.getString("end_date"));
    tb_commpara.setRemark(map.getString("remark"));
    tb_commpara.setUpdate_staff_id(map.getString("update_staff_id"));
    tb_commpara.setUpdate_depart_id(map.getString("update_depart_id"));
    tb_commpara.setUpdate_time(map.getString("update_time"));

    String result_code = "0";
    try {
      update(dbmMgr, tb_commpara);
    } catch (ApplicationException e) {
      e.printStackTrace();
      result_code = "1";
    }
    map.setString("result_code", result_code);
    return map;
  }

  public void update(DbmInterf dbmMgr, Tb_commpara tb_commpara)
    throws ApplicationException
  {
    dbmMgr.update("updateTb_commpara", tb_commpara);
  }

  public List getListByPage(Object obj, int start, int limit)
  {
    Map tb_commpara = (Hashtable)obj;

    if (start == 0)
      start = 0;
    else {
      start = (start - 1) * limit;
    }

    tb_commpara.put("start", Integer.valueOf(start));
    tb_commpara.put("limit", Integer.valueOf(limit));

    return this.queryList.getList("getListByTb_commparaPage", tb_commpara);
  }

  public int getCountByObj(Object obj)
  {
    Map tb_commpara = (Hashtable)obj;
    List list = this.queryList.getList("getCountByObjTb_commpara", tb_commpara);
    int count = 0;
    if ((list != null) && (list.size() > 0)) {
      Hashtable newsMap = (Hashtable)list.get(0);
      if ((newsMap.get("count") != null) && (!newsMap.get("count").toString().equals(""))) {
        count = Integer.parseInt(newsMap.get("count").toString());
      }
    }
    return count;
  }

  public List getListByPk(String pk)
  {
    return this.queryList.getList("getTb_commparaByPk", pk);
  }

  public List getListByCompany(Object obj)
  {
    return this.queryList.getList("getTb_commparaByCompany", obj);
  }

  public Map getCommparaByParam_attr(String param_attr)
  {
    Map comm = new Hashtable();
    comm.put("param_attr", param_attr);
    Map classMap = new Hashtable();
    String para_code2 = ""; String para_code1 = "";
    List list = this.queryList.getList("getCommparaByParam_attr", comm);
    if ((list != null) && (list.size() > 0)) {
      for (int i = 0; i < list.size(); i++) {
        Map map = (Hashtable)list.get(i);
        if (map.get("para_code2") != null) {
          para_code2 = map.get("para_code2").toString();
        }
        if (map.get("para_code1") != null) {
          para_code1 = map.get("para_code1").toString();
        }

        classMap.put(para_code2, para_code1);
      }
    }

    return classMap;
  }

  public String getCustTypeByID(String pk)
  {
    List paraList = this.queryList.getList("getTb_commparaByPk", pk);
    String cust_type = "";
    if ((paraList != null) && (paraList.size() > 0)) {
      Hashtable paraMap = (Hashtable)paraList.get(0);
      if (paraMap.get("para_code1") != null) cust_type = paraMap.get("para_code1").toString();
    }
    return cust_type;
  }

  public String getSelectItem(String param_attr, String para)
  {
    String selectItems = "";
    Map comm = new Hashtable();
    comm.put("param_attr", param_attr);
    //select param_id,param_code,param_name,para_code1,para_code2,para_code3,para_code4,para_code5,para_code6,para_code7,remark from tb_commpara where param_attr=$param_attr$ order by para_code2
    List list = this.queryList.getList("getCommparaByParam_attr", comm);
    Hashtable objMap = new Hashtable();
    String sKey = "";
    String sValue = "";
    if ((list != null) && (list.size() > 0)) {
      for (int i = 0; i < list.size(); i++) {
        objMap = (Hashtable)list.get(i);
        if (objMap.get("para_code2") != null) {
          sKey = objMap.get("para_code2").toString();
        }
        if (objMap.get("para_code1") != null) {
          sValue = objMap.get("para_code1").toString();
        }
        if (para.equals(sKey))
          selectItems = selectItems + "<option selected value=" + sKey + ">" + sValue + "</option>";
        else {
          selectItems = selectItems + "<option value=" + sKey + ">" + sValue + "</option>";
        }
      }
    }
    return selectItems;
  }

  public List getSelectItemToList(String param_attr, String para) {
    Map comm = new Hashtable();
    comm.put("param_attr", param_attr);
    List list = this.queryList.getList("getCommparaByParam_attr", comm);
    return list;
  }

  public String getSelectedValue(String param_attr, String para)
  {
    String SelectedValue = "";
    Map comm = new Hashtable();
    comm.put("param_attr", param_attr);
    List list = this.queryList.getList("getCommparaByParam_attr", comm);
    Hashtable objMap = new Hashtable();
    String sKey = "";
    String sValue = "";
    if ((list != null) && (list.size() > 0)) {
      for (int i = 0; i < list.size(); i++) {
        objMap = (Hashtable)list.get(i);
        if (objMap.get("para_code2") != null) {
          sKey = objMap.get("para_code2").toString();
        }
        if (objMap.get("para_code1") != null) {
          sValue = objMap.get("para_code1").toString();
        }
        if (para.equals(sKey)) {
          SelectedValue = sValue;
          break;
        }
      }
    }
    return SelectedValue;
  }

  public String getRadioItem(String param_attr, String para)
  {
    String selectItems = "";
    Map comm = new Hashtable();
    comm.put("param_attr", param_attr);
    List list = this.queryList.getList("getCommparaByParam_attr", comm);
    Hashtable objMap = new Hashtable();
    String sKey = "";
    String sValue = "";
    String param_code = "";
    if ((list != null) && (list.size() > 0)) {
      for (int i = 0; i < list.size(); i++) {
        objMap = (Hashtable)list.get(i);
        if (objMap.get("param_code") != null) {
          param_code = objMap.get("param_code").toString();
        }
        if (objMap.get("para_code2") != null) {
          sKey = objMap.get("para_code2").toString();
        }
        if (objMap.get("para_code1") != null) {
          sValue = objMap.get("para_code1").toString();
        }
        if (para.equals(sKey))
          selectItems = selectItems + "<input checked type=radio name=" + param_code + " value=" + sKey + " />" + sValue + "<br/>";
        else {
          selectItems = selectItems + "<input type=radio name=" + param_code + " value=" + sKey + " />" + sValue + "<br/>";
        }
      }
    }
    return selectItems;
  }

  public String getRadioItemNo(String param_attr, String para)
  {
    String selectItems = "";
    Map comm = new Hashtable();
    comm.put("param_attr", param_attr);
    List list = this.queryList.getList("getCommparaByParam_attr", comm);
    Hashtable objMap = new Hashtable();
    String sKey = "";
    String sValue = "";
    String param_code = "";
    if ((list != null) && (list.size() > 0)) {
      for (int i = 0; i < list.size(); i++) {
        objMap = (Hashtable)list.get(i);
        if (objMap.get("param_code") != null) {
          param_code = objMap.get("param_code").toString();
        }
        if (objMap.get("para_code2") != null) {
          sKey = objMap.get("para_code2").toString();
        }
        if (objMap.get("para_code1") != null) {
          sValue = objMap.get("para_code1").toString();
        }
        if (para.equals(sKey))
          selectItems = selectItems + "<input checked type=radio name=" + param_code + " value=" + sKey + " />" + sValue;
        else {
          selectItems = selectItems + "<input type=radio name=" + param_code + " value=" + sKey + " />" + sValue;
        }
      }
    }
    return selectItems;
  }

  public List getListByParamAttr(String pk)
  {
    Map comm = new Hashtable();
    comm.put("param_attr", pk);
    return this.queryList.getList("getCommparaByParam_attr", comm);
  }

  public Hashtable getOneCompara(String param_attr, String para_code2)
  {
    Map comm = new Hashtable();
    comm.put("param_attr", param_attr);
    comm.put("para_code2", para_code2);
    List clist = this.queryList.getList("getOneCommpara", comm);
    if ((clist != null) && (clist.size() > 0))
    {
      return (Hashtable)clist.get(0);
    }
    return new Hashtable();
  }

  public Hashtable getMapByParaAttr(String param_attr)
  {
    Map comm = new Hashtable();
    comm.put("param_attr", param_attr);
    List clist = this.queryList.getList("getCommparaByParam_attr", comm);
    Hashtable pMap = new Hashtable();
    if ((clist != null) && (clist.size() > 0))
    {
      Hashtable cMap = new Hashtable();
      for (int i = 0; i < clist.size(); i++) {
        cMap = (Hashtable)clist.get(i);
        String para_code1 = ""; String para_code2 = "";
        if (cMap.get("para_code1") != null) para_code1 = cMap.get("para_code1").toString();
        if (cMap.get("para_code2") != null) para_code2 = cMap.get("para_code2").toString();
        pMap.put(para_code2, para_code1);
      }
    }
    return pMap;
  }

  public Hashtable getOneComparaByP3(String param_attr, String para_code3)
  {
    Map comm = new Hashtable();
    comm.put("param_attr", param_attr);
    comm.put("para_code3", para_code3);
    List clist = this.queryList.getList("getOneCommparaByPCode3", comm);
    if ((clist != null) && (clist.size() > 0))
    {
      return (Hashtable)clist.get(0);
    }
    return new Hashtable();
  }

  public String getOneComparaPcode1(String param_attr, String para_code2)
  {
    Map comm = new Hashtable();
    comm.put("param_attr", param_attr);
    comm.put("para_code2", para_code2);
    String para_code1 = "";
    List clist = this.queryList.getList("getOneCommpara", comm);
    if ((clist != null) && (clist.size() > 0))
    {
      Hashtable coMap = (Hashtable)clist.get(0);
      if (coMap.get("para_code1") != null) para_code1 = coMap.get("para_code1").toString();
    }
    return para_code1;
  }

  public String getOneComparaPcode1ByP3(String param_attr, String para_code3)
  {
    Map comm = new Hashtable();
    comm.put("param_attr", param_attr);
    comm.put("para_code3", para_code3);
    List clist = this.queryList.getList("getOneCommparaByPCode3", comm);
    String para_code1 = "";
    if ((clist != null) && (clist.size() > 0))
    {
      Hashtable coMap = (Hashtable)clist.get(0);
      if (coMap.get("para_code1") != null) para_code1 = coMap.get("para_code1").toString();
    }
    return para_code1;
  }

  public String getSelectItemByID(String param_attr, String paraKey, String paraValue)
  {
    String selectItems = "";
    Map comm = new Hashtable();
    comm.put("param_attr", param_attr);
    List list = this.queryList.getList("getCommparaByParam_attr", comm);
    Hashtable objMap = new Hashtable();
    String sKey = "";
    String sValue = "";
    if ((list != null) && (list.size() > 0)) {
      for (int i = 0; i < list.size(); i++) {
        objMap = (Hashtable)list.get(i);
        if (objMap.get(paraKey) != null) {
          sKey = objMap.get(paraKey).toString();
        }
        if (objMap.get(paraValue) != null) {
          sValue = objMap.get(paraValue).toString();
        }
        if (paraKey.equals(sKey))
          selectItems = selectItems + "<option selected value=" + sKey + ">" + sValue + "</option>";
        else {
          selectItems = selectItems + "<option value=" + sKey + ">" + sValue + "</option>";
        }
      }
    }
    return selectItems;
  }

  public String getCheckBoxString(String param_attr, String checkboxName, String paraKey, String paraValue, String params)
  {
    String selectItems = "";
    Map comm = new Hashtable();
    comm.put("param_attr", param_attr);
    List list = this.queryList.getList("getCommparaByParam_attr", comm);
    Hashtable objMap = new Hashtable();
    String sKey = "";
    String sValue = "";
    if ((list != null) && (list.size() > 0)) {
      for (int i = 0; i < list.size(); i++) {
        objMap = (Hashtable)list.get(i);
        if (objMap.get(paraKey) != null) {
          sKey = objMap.get(paraKey).toString();
        }
        if (objMap.get(paraValue) != null) {
          sValue = objMap.get(paraValue).toString();
        }
        if (params.indexOf(sKey) >= 0)
          selectItems = selectItems + "<input type='checkbox' name='" + checkboxName + "' id='" + checkboxName + "_" + sKey + "' value='" + sKey + "' checked>" + sValue + "&nbsp;";
        else {
          selectItems = selectItems + "<input type='checkbox' name='" + checkboxName + "' id='" + checkboxName + "_" + sKey + "' value='" + sKey + "'>" + sValue + "&nbsp;";
        }
      }
    }
    return selectItems;
  }

  public String getDisplayString(String param_attr, String paraKey, String paraValue, String params)
  {
    String selectItems = "";
    Map comm = new Hashtable();
    comm.put("param_attr", param_attr);
    List list = this.queryList.getList("getCommparaByParam_attr", comm);
    Hashtable objMap = new Hashtable();
    String sKey = "";
    String sValue = "";
    if ((list != null) && (list.size() > 0)) {
      for (int i = 0; i < list.size(); i++) {
        objMap = (Hashtable)list.get(i);
        if (objMap.get(paraKey) != null) {
          sKey = objMap.get(paraKey).toString();
        }
        if (objMap.get(paraValue) != null) {
          sValue = objMap.get(paraValue).toString();
        }
        if (params.indexOf(sKey) >= 0) {
          selectItems = selectItems + sValue + "&nbsp;";
        }
      }
    }
    return selectItems;
  }

  public String getOneComparaPcode2ByP3(String param_attr, String para_code3)
  {
    Map comm = new Hashtable();
    comm.put("param_attr", param_attr);
    comm.put("para_code3", para_code3);
    List clist = this.queryList.getList("getOneCommparaByPCode3", comm);
    String para_code1 = "";
    if ((clist != null) && (clist.size() > 0))
    {
      Hashtable coMap = (Hashtable)clist.get(0);
      if (coMap.get("para_code2") != null) para_code1 = coMap.get("para_code2").toString();
    }
    return para_code1;
  }

  public List getListComparaByP3(String param_attr, String para_code3)
  {
    Map comm = new Hashtable();
    comm.put("param_attr", param_attr);
    comm.put("para_code3", para_code3);
    List clist = this.queryList.getList("getOneCommparaByPCode3", comm);

    return clist;
  }

  public String getOnCPcode2Byparam_attr(String param_attr)
  {
    Map comm = new Hashtable();
    comm.put("param_attr", param_attr);
    List clist = this.queryList.getList("getOneCommparaCP2", comm);
    String para_code2 = "";
    if ((clist != null) && (clist.size() > 0))
    {
      Hashtable coMap = (Hashtable)clist.get(0);
      if (coMap.get("para_code2") != null) para_code2 = coMap.get("para_code2").toString();
    }
    return para_code2;
  }

  public List getListByCode2(Object obj)
  {
    return this.queryList.getList("getCommparaByPCode2", obj);
  }

  public Hashtable getHashtableByCode2(Hashtable map) {
    Hashtable cmap = new Hashtable();
    List clist = this.queryList.getList("getCommparaByPCode2", map);
    if ((clist != null) && (clist.size() > 0))
    {
      cmap = (Hashtable)clist.get(0);
    }
    return cmap;
  }
}